﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Text;

namespace Project.Home
{
    public partial class WebForm7 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string url = Convert.ToString(Request.QueryString["url"]);
            string content = GetHTML(url);
            int t = 0;
            int b = 0;
            t = content.IndexOf("<div class=\"content\"");
            if (t > 0) content = content.Substring(t + 21, content.Length - t - 22);
            b = content.LastIndexOf("class=\"tag-parent\"");
            content = content.Substring(0, b - 5);

            content = content.Replace("http://vnexpress.net", "NewsRss.aspx?url=http://vnexpress.net");
            content = content.Replace("\"/gl/", "NewsRss.aspx?url=http://vnexpress.net/gl/");
            content = content.Replace("/Files", "http://vnexpress.net/Files");
            content = content.Replace("/Library", "http://vnexpress.net/Library");
            content = content.Replace("/Images", "http://vnexpress.net/Images");
            content = content.Replace("/Service", "http://vnexpress.net/Service");

            Label1.Text = content;
        }

        public string GetHTML(string url)
        {
            if (string.IsNullOrEmpty(url))
            {
                return "";
            }
            string html = "";
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream responseStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
            html = reader.ReadToEnd();
            response.Close();
            reader.Close();
            return html;
        }
    }
}